home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SNNSV32.ZIP / SNNSv3.2 / kernel / sources / arttr_f.c < prev    next >
C/C++ Source or Header  |  1994-04-25  |  10KB  |  453 lines

  1. /*****************************************************************************
  2.   FILE           : arttr_f.c
  3.   SHORTNAME      : 
  4.   SNNS VERSION   : 3.2
  5.  
  6.   PURPOSE        : SNNS-Kernel special transfer functions for ART-networks
  7.   NOTES          :
  8.  
  9.   AUTHOR         : Kai-Uwe Herrmann
  10.   DATE           : 17.05.92
  11.  
  12.   CHANGED BY     : Sven Doering
  13.   IDENTIFICATION : @(#)arttr_f.c    1.9 3/15/94
  14.   SCCS VERSION   : 1.9
  15.   LAST CHANGE    : 3/15/94
  16.  
  17.              Copyright (c) 1990-1994  SNNS Group, IPVR, Univ. Stuttgart, FRG
  18.  
  19. ******************************************************************************/
  20. #include <math.h>
  21. #include <string.h>
  22. #include <values.h>
  23.  
  24. #include "kr_typ.h"        /* Kernel types and constants  */
  25. #include "kr_def.h"        /* Default values    */
  26. #include "kr_const.h"   /* constant values of kernel */
  27. #include "func_mac.h"   /* Transfer function macros  */
  28. #include "glob_typ.h"
  29.  
  30. #include "kr_art.h"     /* global definitions especially for ART networks */
  31. #include "kr_art1.h"
  32. #include "kr_art2.h"
  33. #include "kr_amap.h"
  34. #include "krart_df.h"
  35.  
  36. #include "arttr_f.ph"
  37.  
  38. /*#################################################
  39.  
  40. GROUP: Unit Output Functions
  41.  
  42. #################################################*/
  43.  
  44.  
  45. /*######### for ART2 model ##########*/
  46.  
  47. /* This is one of the possible noise function f which works
  48.    between q and v, and x and v units in the F1-Layer in ART2-networks.
  49.  
  50.               |-
  51.               |  0, if 0 <= x < Theta
  52.        f(x) = |
  53.               | x, if x >= Theta
  54.               |-
  55.   It is piecewise linear (PLin)
  56. */
  57. FlintType  OUT_ART2_Noise_PLin (register FlintType activation)
  58. {
  59.    if (activation < kra2_get_theta()) {
  60.       return (0.0);
  61.    } else {
  62.       return (activation);
  63.    } /*if*/
  64. } /* OUT_ART2_Noise_PLin () */
  65.  
  66.  
  67. /* This is one of the possible noise function f which works
  68.    between q and v, and x and v units in the F1-Layer in ART2-networks.
  69.  
  70.               |-
  71.               |  (2*Theta*x*x) / (x*x + Theta*Theta), if 0 <= x < Theta
  72.        f(x) = |
  73.               |  x                                  , if x >= Theta
  74.               |-
  75.  
  76.    It is continously differentiable (ContDiff)
  77. */
  78. FlintType  OUT_ART2_Noise_ContDiff (FlintType activation)
  79. {
  80.    register FlintType theta;
  81.  
  82.    theta = kra2_get_theta();
  83.  
  84.    if ((0 <= activation) && (activation < theta)) {
  85.       return ( (2*theta*activation*activation) /
  86.                (activation*activation+theta*theta)
  87.              );
  88.    } else {
  89.       if (activation >= theta) {
  90.          return (activation);
  91.       } else {
  92.          return (0.0);
  93.       } /*if*/
  94.    } /*if*/
  95. } /* OUT_ART2_Noise_ContDiff () */
  96.  
  97.  
  98.  
  99.  
  100.  
  101. /*#################################################
  102.  
  103. GROUP: Unit Activation Functions
  104.  
  105. #################################################*/
  106.  
  107.  
  108. /*######### for ART1 model ##########*/
  109.  
  110.  
  111. FlintType  ACT_ART1_NC  (struct Unit *unit_ptr)
  112. {
  113.    ACT_FUNC_DEFS
  114.    register FlintType     sum = 0.0;
  115.  
  116.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  117.       do {
  118.          sum += GET_WEIGHTED_OUTPUT;
  119.       } while (GET_NEXT_LINK);
  120.    } else {
  121.       if (GET_FIRST_SITE (unit_ptr)) {
  122.          do {
  123.             sum += GET_SITE_VALUE;
  124.          } while (GET_NEXT_SITE);
  125.       } /*if*/
  126.    } /*if*/
  127.  
  128.    if (((int) (sum+0.5)) >= Art1_NoOfRecUnits) {
  129.       return (1.0);
  130.    } else {
  131.       return (0.0);
  132.    } /*if*/
  133. } /* ACT_ART1_NC () */
  134.  
  135.  
  136. /*######### for ART2 model ##########*/
  137.  
  138.  
  139. FlintType ACT_ART2_Linear (struct Unit *unit_ptr)
  140. {
  141.    ACT_FUNC_DEFS
  142.    register FlintType     sum = 0.0;
  143.  
  144.    if (kra2_Reset()) {
  145.       return (unit_ptr->i_act);
  146.    } /*if*/
  147.  
  148.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  149.       do {
  150.          sum += GET_WEIGHTED_OUTPUT;
  151.       } while (GET_NEXT_LINK);
  152.    } else {
  153.       if (GET_FIRST_SITE (unit_ptr)) {
  154.          do {
  155.             sum += GET_SITE_VALUE;
  156.          } while (GET_NEXT_SITE);
  157.       } /*if*/
  158.    } /*if*/
  159.  
  160.    return (sum);
  161. } /* ACT_ART2_Linear () */
  162.  
  163.  
  164.  
  165. FlintType ACT_ART2_NormP  (struct Unit *unit_ptr)
  166. {
  167.    ACT_FUNC_DEFS
  168.    FlintType              NormP;
  169.    register FlintType     sum = 0.0;
  170.  
  171.    if (kra2_Reset()) {
  172.       return (unit_ptr->i_act);
  173.    } /*if*/
  174.  
  175.    NormP = kra2_L2_Norm (ART2_P_LAY);
  176.  
  177.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  178.       do {
  179.          sum += GET_WEIGHTED_OUTPUT;
  180.       } while (GET_NEXT_LINK);
  181.    } else {
  182.       if (GET_FIRST_SITE (unit_ptr)) {
  183.          do {
  184.             sum += GET_SITE_VALUE;
  185.          } while (GET_NEXT_SITE);
  186.       } /*if*/
  187.    } /*if*/
  188.  
  189.    return ( sum / (ART2_PARAM_e + NormP) );
  190. } /* ACT_ART2_NormP() */
  191.  
  192.  
  193.  
  194. FlintType ACT_ART2_NormV  (struct Unit *unit_ptr)
  195. {
  196.    ACT_FUNC_DEFS
  197.    FlintType              NormV;
  198.    register FlintType     sum = 0.0;
  199.  
  200.    if (kra2_Reset()) {
  201.       return (unit_ptr->i_act);
  202.    } /*if*/
  203.  
  204.    NormV = kra2_L2_Norm (ART2_V_LAY);
  205.  
  206.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  207.       do {
  208.          sum += GET_WEIGHTED_OUTPUT;
  209.       } while (GET_NEXT_LINK);
  210.    } else {
  211.       if (GET_FIRST_SITE (unit_ptr)) {
  212.          do {
  213.             sum += GET_SITE_VALUE;
  214.          } while (GET_NEXT_SITE);
  215.       } /*if*/
  216.    } /*if*/
  217.  
  218.    return ( sum / (ART2_PARAM_e + NormV) );
  219. } /* ACT_ART2_NormV() */
  220.  
  221.  
  222.  
  223. FlintType ACT_ART2_NormW  (struct Unit *unit_ptr)
  224. {
  225.    ACT_FUNC_DEFS
  226.    FlintType              NormW;
  227.    register FlintType     sum  = 0.0;
  228.  
  229.    if (kra2_Reset()) {
  230.       return (unit_ptr->i_act);
  231.    } /*if*/
  232.  
  233.    NormW = kra2_L2_Norm (ART2_W_LAY);
  234.  
  235.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  236.       do {
  237.          sum += GET_WEIGHTED_OUTPUT;
  238.       } while (GET_NEXT_LINK);
  239.    } else {
  240.       if (GET_FIRST_SITE (unit_ptr)) {
  241.          do {
  242.             sum += GET_SITE_VALUE;
  243.          } while (GET_NEXT_SITE);
  244.       } /*if*/
  245.    } /*if*/
  246.  
  247.    return ( sum / (ART2_PARAM_e + NormW) );
  248. } /* ACT_ART2_NormW() */
  249.  
  250.  
  251.  
  252. FlintType ACT_ART2_NormIP  (struct Unit *unit_ptr)
  253. {
  254.    ACT_FUNC_DEFS
  255.    FlintType              NormP;
  256.    FlintType              NormInp;
  257.    register FlintType     sum = 0.0;
  258.  
  259.    if (kra2_Reset()) {
  260.       return (unit_ptr->i_act);
  261.    } /*if*/
  262.  
  263.    NormP   = kra2_L2_Norm (ART2_P_LAY);
  264.    NormInp = kra2_L2_Norm (ART2_INP_LAY);
  265.  
  266.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  267.       do {
  268.          sum += GET_WEIGHTED_OUTPUT;
  269.       } while (GET_NEXT_LINK);
  270.    } else {
  271.       if (GET_FIRST_SITE (unit_ptr)) {
  272.          do {
  273.             sum += GET_SITE_VALUE;
  274.          } while (GET_NEXT_SITE);
  275.       } /*if*/
  276.    } /*if*/
  277.  
  278.    return ( sum / (ART2_PARAM_e + kra2_get_c() * NormP + NormInp) );
  279. } /* ACT_ART2_NormIP() */
  280.  
  281.  
  282.  
  283.  
  284. FlintType ACT_ART2_Rec  (struct Unit *unit_ptr)
  285. {
  286.    ACT_FUNC_DEFS
  287.    register FlintType     sum  = 0.0;
  288.  
  289.  
  290.    /* Top Down Phase */
  291.    if (kra2_topdn_phase()) {
  292.       if (kra2_Reset()) {
  293.          return (-1.0);
  294.       } else {
  295.          return (unit_ptr->act);
  296.       } /*if*/
  297.    } /*if*/
  298.  
  299.  
  300.    /* Bottom Up Phase */
  301.    if ( ! kra2_f1_stable() ) {
  302.       return (-1.0);
  303.    } /*if*/
  304.  
  305.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  306.       do {
  307.          sum += GET_WEIGHTED_OUTPUT;
  308.       } while (GET_NEXT_LINK);
  309.    } else {
  310.       if (GET_FIRST_SITE (unit_ptr)) {
  311.          do {
  312.             sum += GET_SITE_VALUE;
  313.          } while (GET_NEXT_SITE);
  314.       } /*if*/
  315.    } /*if*/
  316.  
  317.    return (sum);
  318. } /* ACT_ART2_Rec() */
  319.  
  320.  
  321.  
  322.  
  323. FlintType ACT_ART2_Rst  (struct Unit *unit_ptr)
  324. {
  325.    ACT_FUNC_DEFS
  326.    register FlintType     sum  = 0.0;
  327.  
  328.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  329.       do {
  330.          sum += GET_WEIGHTED_OUTPUT;
  331.       } while (GET_NEXT_LINK);
  332.    } else {
  333.       if (GET_FIRST_SITE (unit_ptr)) {
  334.          do {
  335.             sum += GET_SITE_VALUE;
  336.          } while (GET_NEXT_SITE);
  337.       } /*if*/
  338.    } /*if*/
  339.  
  340.    if (((sum >= unit_ptr->bias - 0.0001) &&
  341.        (kra2_Reset())) || (unit_ptr->act >= 0.9))
  342.    {
  343.       return (1.0);
  344.    } else {
  345.       return (0.0);
  346.    } /*if*/
  347. } /* ACT_ART2_Rst () */
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358. /*######### for ARTMAP model ##########*/
  359.  
  360.  
  361. FlintType  ACT_ARTMAP_NCa  (struct Unit *unit_ptr)
  362. {
  363.    ACT_FUNC_DEFS
  364.    register FlintType     sum = 0.0;
  365.  
  366.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  367.       do {
  368.          sum += GET_WEIGHTED_OUTPUT;
  369.       } while (GET_NEXT_LINK);
  370.    } else {
  371.       if (GET_FIRST_SITE (unit_ptr)) {
  372.          do {
  373.             sum += GET_SITE_VALUE;
  374.          } while (GET_NEXT_SITE);
  375.       } /*if*/
  376.    } /*if*/
  377.  
  378.    if (((int) (sum+0.5)) >= ArtMap_NoOfRecUnits_a) {
  379.       return (1.0);
  380.    } else {
  381.       return (0.0);
  382.    } /*if*/
  383. } /* ACT_ARTMAP_NCa () */
  384.  
  385.  
  386. FlintType  ACT_ARTMAP_NCb  (struct Unit *unit_ptr)
  387. {
  388.    ACT_FUNC_DEFS
  389.    register FlintType     sum = 0.0;
  390.  
  391.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  392.       do {
  393.          sum += GET_WEIGHTED_OUTPUT;
  394.       } while (GET_NEXT_LINK);
  395.    } else {
  396.       if (GET_FIRST_SITE (unit_ptr)) {
  397.          do {
  398.             sum += GET_SITE_VALUE;
  399.          } while (GET_NEXT_SITE);
  400.       } /*if*/
  401.    } /*if*/
  402.  
  403.    if (((int) (sum+0.5)) >= ArtMap_NoOfRecUnits_b) {
  404.       return (1.0);
  405.    } else {
  406.       return (0.0);
  407.    } /*if*/
  408. } /* ACT_ARTMAP_NCb () */
  409.  
  410.  
  411.  
  412. /* This is an important function for ARTMAP networks
  413.    it calculates the net input to the drho unit (sum)
  414.    If sum is greater than 0 then the activation of
  415.    drho becomes  sum-1+epsilon where epsilon << 1
  416. */
  417. FlintType  ACT_ARTMAP_DRho (struct Unit *unit_ptr)
  418. {
  419.    ACT_FUNC_DEFS
  420.    register FlintType    sum = 0.0;
  421.    float                 epsilon = 0.0001;
  422.  
  423.  
  424.    if (GET_FIRST_UNIT_LINK (unit_ptr)) {
  425.       do {
  426.          sum += GET_WEIGHTED_OUTPUT;
  427.       } while (GET_NEXT_LINK);
  428.    } else {
  429.       if (GET_FIRST_SITE (unit_ptr)) {
  430.          do {
  431.             sum += GET_SITE_VALUE;
  432.          } while (GET_NEXT_SITE);
  433.       } /*if*/
  434.    } /*if*/
  435.  
  436.    /* sum equals     (qu - rho_a + rg + cl_b) */
  437.    if (sum - 2 >= 0) {
  438.       return (sum - 2 + epsilon);
  439.    } else {
  440.       return (0.0);
  441.    } /*if*/
  442.  
  443. } /* ACT_ARTMAP_DRho () */
  444.  
  445.  
  446.  
  447.  
  448. /*#################################################
  449.  
  450. GROUP: Site Functions
  451.  
  452. #################################################*/
  453.